package 多线程.多线程出错解决办法_同步代码块;
public class 用户 extends Thread {
    public String name;
    public 用户(String name) {
        this.name = name;
    }
    @Override
    public void run() {
        synchronized (银行.锁) {
            if(银行.余额 >=100){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                银行.余额 -=100;
                System.out.println(name+"取了100元~~"+"银行还剩"+银行.余额);
            }
            else{
                System.out.println("银行的余额不足100元~~");
            }
        }
    }
}
